"""
GUI TEST RUNNER
Run by Typing: "python gui_test_runner.py"
(Use Python 3 - There are GUI issues when using Python 2)
"""

import os
from tkinter import Tk, Frame, Button, Label


class App:
    def __init__(self, master, test):
        self.test = test
        frame = Frame(master)
        frame.pack()
        self.label = Label(root, width=40).pack()
        self.title = Label(frame, text="", fg="black").pack()

        self.title1 = Label(frame, text=("Run a Test in Chrome:"), fg="blue", ).pack()
        self.run1 = Button(frame, command=self.run_1, text=(f"pytest {self.test} --browser=chrome"), fg="green", ).pack()

        self.title2 = Label(frame, text=("Run a Test in Firefox:"), fg="blue", ).pack()
        self.run2 = Button(frame, command=self.run_2, text=(f"pytest {self.test} --browser=firefox"), fg="green", ).pack()

        self.title8 = Label(frame, text="Run a Test with ie:", fg="blue", ).pack()
        self.run8 = Button(frame, command=self.run_8, text=(f"pytest {self.test} --browser=ie"), fg="green", ).pack()

        self.title5 = Label(frame,text="Run a Test in edge :",fg="blue",).pack()
        self.run5 = Button(frame,command=self.run_5,text=(f"pytest {self.test} --browser=edge"),fg="green",).pack()

        self.title3 = Label(frame,text="Run a Test with Demo:",fg="blue",).pack()
        self.run3 = Button(frame,command=self.run_3,text=(f"pytest {self.test} --demo --reuse-session"),fg="green",).pack()

        self.title4 = Label(frame,text="Run a Test with 无GUI :",fg="blue",).pack()
        self.run4 = Button(frame,command=self.run_4,text=(f"pytest {self.test} --headless"),fg="green",).pack()

        self.title6 = Label(frame,text="Run a Test Suite with a Test Report:",fg="blue",).pack()
        self.run6 = Button(frame,command=self.run_6,text=(f"pytest {self.test} --html=report.html --reuse-session"),fg="green",).pack()


        self.end_title = Label(frame, text="", fg="black").pack()
        self.quit = Button(frame, text="QUIT", command=frame.quit).pack()

    def run_1(self):
        os.system(f"pytest -s {self.test} --browser=chrome")

    def run_2(self):
        os.system(f"pytest {self.test} --browser=firefox")

    def run_3(self):
        os.system(f"pytest {self.test} --demo --reuse-session")

    def run_4(self):
        os.system(f"pytest {self.test} --headless")

    def run_5(self):
        os.system(f"pytest {self.test} --browser=edge")

    def run_6(self):
        os.system(f"pytest {self.test} --html=report.html --reuse-session")

    def run_8(self):
        os.system(f"pytest {self.test} --browser=ie")


if __name__ == "__main__":

    # 请输入你要测试的测试用例
    test = "test_001.py"

    # 此处不用管
    root = Tk()
    root.title("运行测试用例GUI界面")
    root.minsize(500, 500)
    app = App(root, test)
    root.mainloop()
